#include <cstdio>
#include <memory.h>
#include <cmath>

struct Matrix
{
    int n, m;
    double a[ 4 ][ 4 ];
};

void operator *= ( Matrix &a, const Matrix &b )
{
    Matrix c;
    int i, j, k;
    c.n = a.n; c.m = b.m;
    memset( c.a, 0, sizeof( c.a ) );
    for ( i = 0; i < a.n; i++ )
        for ( j = 0; j < a.m; j++ )
            for ( k = 0; k < b.m; k++ )
                c.a[ i ][ k ] += a.a[ i ][ j ] * b.a[ j ][ k ];
    a = c;
}

int main( )
{
    int i, j, k, t, xx, yy, zz;
    char cmd[ 200 ];
    Matrix a, b, q;
    double x, y, z, p, cs, sn, mo;
    scanf("%d", &t);
    gets( cmd );
    while ( t-- )
    {
        memset( a.a, 0, sizeof( a.a ) );
        b.n = b.m = a.n = a.m = 4;
        q.n = 4; q.m = 1;
        a.a[ 0 ][ 0 ] = a.a[ 1 ][ 1 ] = a.a[ 2 ][ 2 ] = a.a[ 3 ][ 3 ] = 1;
        scanf("%s", cmd);
        while ( scanf("%s", cmd) )
        {
            memset( b.a, 0, sizeof( b.a ) );
            if ( cmd[ 2 ] == 'S' )
            {
                sscanf(cmd, "glScalef(%lf,%lf,%lf);", &x, &y, &z);
                b.a[ 0 ][ 0 ] = x; b.a[ 1 ][ 1 ] = y; b.a[ 2 ][ 2 ] = z; b.a[ 3 ][ 3 ] = 1;
                a *= b;
            }
            if ( cmd[ 2 ] == 'T' )
            {
                sscanf(cmd, "glTranslatef(%lf,%lf,%lf);", &x, &y, &z);
                b.a[ 0 ][ 3 ] = x; b.a[ 1 ][ 3 ] = y; b.a[ 2 ][ 3 ] = z; 
                b.a[ 0 ][ 0 ] = b.a[ 1 ][ 1 ] = b.a[ 2 ][ 2 ] = b.a[ 3 ][ 3 ] = 1;
                a *= b;
            }
            if ( cmd[ 2 ] == 'R' )
            {
                sscanf(cmd, "glRotatef(%lf,%lf,%lf,%lf);", &p, &x, &y, &z);
                mo = sqrt( x * x + y * y + z * z );
                x /= mo; y /= mo; z /= mo;
                cs = cos( p ); sn = sin( p );
                b.a[ 0 ][ 0 ] = x * x * ( 1 - cs ) + cs;
                b.a[ 0 ][ 1 ] = x * y * ( 1 - cs ) - z * sn;
                b.a[ 0 ][ 2 ] = x * z * ( 1 - cs ) + y * sn;
                b.a[ 1 ][ 0 ] = x * y * ( 1 - cs ) + z * sn;
                b.a[ 1 ][ 1 ] = y * y * ( 1 - cs ) + cs;
                b.a[ 1 ][ 2 ] = y * z * ( 1 - cs ) - x * sn;
                b.a[ 2 ][ 0 ] = x * z * ( 1 - cs ) - y * sn;
                b.a[ 2 ][ 1 ] = y * z * ( 1 - cs ) + x * sn;
                b.a[ 2 ][ 2 ] = z * z * ( 1 - cs ) + cs;
                b.a[ 0 ][ 3 ] = b.a[ 1 ][ 3 ] = b.a[ 2 ][ 3 ] = b.a[ 3 ][ 0 ] = b.a[ 3 ][ 1 ] = b.a[ 3 ][ 2 ] = 0;
                b.a[ 3 ][ 3 ] = 1;
                a *= b;
            }
            if ( cmd[ 2 ] == 'V' )
            {
                sscanf(cmd, "glVertex3f(%lf,%lf,%lf);", &q.a[ 0 ][ 0 ], &q.a[ 1 ][ 0 ], &q.a[ 2 ][ 0 ]);
                q.a[ 3 ][ 0 ] = 1;
                a *= q;
                scanf("%s", cmd);
                break;
            }
        }
        printf("%.1lf %.1lf %.1lf\n", a.a[ 0 ][ 0 ], a.a[ 1 ][ 0 ], a.a[ 2 ][ 0 ]);
    }
    return 0;
}
